package com.jzo2o.orders.manager.client;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jzo2o.api.customer.AddressBookApi;
import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 调用customer的客户端类
 */
@Component
@Slf4j
public class CustomerClient {
    @Resource
    private AddressBookApi addressBookApi;
    /**
     * 根据ID查询地址簿
     */
    @SentinelResource(value = "getAddressBookDetail" ,fallback = "detailFallback",blockHandler = "detailBlockHandler")
    public AddressBookResDTO getAddressBookDetail(Long id) {
        return addressBookApi.detail(id);
    }

    /***
     * 根据ID查询地址簿【降级处理方法】
     */
    public AddressBookResDTO detailFallback(Long id, Throwable throwable){
        log.error("普通降级处理，id=:{}，异常信息：{}",id,throwable);
        return null;
    }

    /***
     * 根据ID查询地址簿【熔断处理方法】
     */
    public AddressBookResDTO detailBlockHandler(Long id, BlockException blockException){
        log.error("熔断降级处理，id=:{}，异常信息：{}",id,blockException);
        return null;
    }
}
